package com.gwnet.shop.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.log.annotation.Log;
import com.gwnet.common.log.enums.BusinessType;
import com.gwnet.common.mybatis.core.page.TableDataInfo;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.shop.domain.SpecGroup;
import com.gwnet.shop.service.ISpecGroupService;
import com.gwnet.shop.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品规格组合价格Controller
 * @author 张万鹏
 * @date 2024-07-21
 */
@RestController
@RequestMapping("/specgroup")
public class SpecGroupController extends MBaseController
{
    @Resource
    private ISpecGroupService specGroupService;

    /**
     * 查询商品规格组合价格列表
     */
    @SaCheckPermission("shop:specgroup:list")
    @GetMapping("/list")
    public TableDataInfo list(SpecGroup specGroup)
    {
        startPage();
        List<SpecGroup> list = specGroupService.selectSpecGroupList(specGroup);
        return getDataTable(list);
    }


    /**
     * 获取商品规格组合价格详细信息
     */
    @SaCheckPermission("shop:specgroup:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(specGroupService.selectSpecGroupById(id));
    }

    /**
     * 新增商品规格组合价格
     */
    @SaCheckPermission("shop:specgroup:add")
    @Log(title = "商品规格组合价格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpecGroup specGroup)
    {
        specGroup.setCreateBy( LoginHelper.getUserId() );
        return toAjax(specGroupService.insertSpecGroup(specGroup));
    }

    /**
     * 批量新增商品规格组合价格
     */
    @SaCheckPermission("shop:specgroup:add")
    @Log(title = "商品规格组合价格", businessType = BusinessType.INSERT)
    @PostMapping("/list")
    public AjaxResult add(@RequestBody List<SpecGroup> list)
    {
        return toAjax(specGroupService.insertSpecGroup(list));
    }

    /**
     * 修改商品规格组合价格
     */
    @SaCheckPermission("shop:specgroup:edit")
    @Log(title = "商品规格组合价格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpecGroup specGroup)
    {
        specGroup.setCreateBy( LoginHelper.getUserId() );
        return toAjax(specGroupService.updateSpecGroup(specGroup));
    }

    /**
     * 删除商品规格组合价格
     */
    @SaCheckPermission("shop:specgroup:remove")
    @Log(title = "商品规格组合价格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(specGroupService.deleteSpecGroupByIds(ids));
    }
}
